<?php
//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
//created object for page.php
$page = new page();
session_start();

if (!$_SESSION['username']) {
    header("location:../user/login.php");
}

if ($_GET['q'] == 'logout') {
    $page->user_logout();
    header("location:../user/login.php");
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    if ($_POST['chkDel'] == "") {
        $msg = $message[8];
    } else {
        $result = $page->group_delete("groupid", "groups", $_POST['chkDel']);
        if ($result) {
            $msg = $message[2];
        } else {
            $msg = $message[0] . '<br/ >or<br />' . $message[5];
        }
    }
}
if ($_GET['status']) {
    $msg = $message[3];
}
$group = 'active';
include '../../include/navbar.php';
?>
<?
//start the buffer
ob_start();
?>
<!------------------css style sheets for responsive tables------------------------------------>
<link rel="stylesheet" type="text/css" href="../../css/groups/style_table.css">
<link rel="stylesheet" type="text/css" href="../../css/groups/responsive_table.css">

<!-------------------------------------------Group selection options----------------->
<div class="group_select_desk">
    <span><strong style="font-size:22px;">Groups</strong>
        <!---  <a onclick="javascript:checkAll('frmMain', false);" href="javascript:void();" style="float:right">uncheck all</a>
          <a onclick="javascript:checkAll('frmMain', true);" href="javascript:void();" style="float:right; margin-right: 20px;">check all</a></span>-->
        <a href="javascript:reserveCheck('chkDel[]')" style="float:right">Invert Select</a>
        <a href="javascript:allCheck('chkDel[]',false)" style="float:right; margin-right: 20px;">Select None</a> 
        <a href="javascript:allCheck('chkDel[]',true)" style="float:right; margin-right: 20px;">Select All</a></span>
</div>
<div class="group_select_mob">
    <span><strong style="font-size:22px;">Groups</strong>
        <div class="btn-group"  style="float: right">
            <a class="btn dropdown-toggle" data-toggle="dropdown" href="#" >
                Select&nbsp;
                <span class="caret"></span>
            </a>
            <ul class="dropdown-menu"  style="float:left;margin-left: -84px">
                <!-- dropdown menu links -->
                <li><a href="javascript:allCheck('chkDel[]',true)">Select All</a></li>
                <li><a href="javascript:allCheck('chkDel[]',false)">Select None</a></li> 
                <li><a href="javascript:reserveCheck('chkDel[]')" >Invert Select</a></li> 
            </ul>
        </div>



    </span>
</div>
<br />

<!------------------------------Form------------------------------------->
<form name="yourname"" action="" method="post" OnSubmit="return onDelete();">

    <!------------------------------Details Table------------------------------------->
    <table  class="table1 table-striped" style="margin-left: auto;margin-right: auto; ">
        <thead  class="thead1">
            <tr>
                <th class="row_desktop"></th>
                <th>SL NO</th>
                <th>Name</th>
                <th>Active</th>
                <th>Edit</th>
            </tr>
        </thead>
        <tbody>
            <?php
            //php code to get the data from groups table 
            $groups = mysql_query("select * from groups");
            $id = 0;
            while ($groups_data = mysql_fetch_array($groups)) {

                $group_id = $groups_data['groupid'];
                $name = ucwords(strtolower($groups_data['name']));
                //$created_user = ucwords(strtolower($groups_data['c_user']));
                //$created_date = $groups_data['c_date'];
                //$modified_user = ucwords(strtolower($groups_data['m_user']));
                //$modified_date = $groups_data['m_date'];
                $active = $groups_data['active'];
                $id++;
                ?>

                <!-------------------------Dynamic row to display from database--------------------->
                <tr>
                    <td><input type="checkbox" name="chkDel[]" id="choice" value="<? echo $group_id; ?>"></td>
                    <td><? echo $id; ?></td>
                    <td><a href="group_update?id=<? echo $group_id; ?>"><? echo $name; ?></a></td>
                    <td><? echo $active; ?></td>
                    <td><a href="group_update?id=<? echo $group_id; ?>">Edit</a></td>
                </tr>

                <?php
                // Closing the loop
            }
            ?>
        </tbody>
    </table>

    <!----------------------------------Display the result message of deletion--------------------->
    <div  align="center" style="margin-top: 10px;"><? echo $msg; ?></div>

    <!----------------------------CRUD Buttons-------------------------------------->
    <div align="center" style="margin-top: 10px;">
        <a href="group_add"><button class="btn btn-primary" type="button">Add</button></a>
        <!-----<button class="btn btn-inverse" type="button">Update</button>----->
        <button class="btn btn-danger" type="submit">Delete</button>
    </div>
</form> 


<?php
//including footer.php
include '../../include/footer.php';
//flush the buffer
flush();
?>
